new Vue({
    el: "#container",
    data() {
        return {
            tableSearch: {
                offset: 0,
                limit: 50,
                total: 0,
                dateFormat: "yyyy-MM-dd HH:mm",
                endTime: null,
                startTime: null,
                busName: "",
            },
            //  表数据
            tableDatas: [],
            tableLoading: false,
        }
    },
    // 在模板渲染成html前调用
    created() {
        var that = this;
        that.loadTableDatas();
    },
    // 在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作
    mounted() {
        var that = this;
    },
    methods: {
        searchDatas() {
            let that = this;
            that.tableSearch.offset = 0;
            that.tableSearch.limit = 50;
            that.loadTableDatas();
        },
        // 加载数据
        loadTableDatas: function () {
            let that = this;
            that.tableLoading = true;
            $.ajax({
                type: "POST",
                url: "/weight/order/unskinned/page",
                async: true,
                dataType: 'json',
                data: that.tableSearch,
                success: function (res) {
                    if (res.code == 0) {
                        let page = res.data;
                        let records = page.records;
                        if (records != null && records.length > 0) {
                            $.each(records, function (i, item) {
                                let imgUrl = item.imgUrl;
                                item.img = {
                                    pre: imgUrl,
                                    urls: [imgUrl],
                                };
                            })
                        }
                        that.tableDatas = records;
                        that.tableSearch.total = page.total;
                    } else {
                        that.$message({
                            showClose: true,
                            message: '查询过磅记录失败：' + res.msg,
                            type: 'error'
                        });
                    }
                },
                error: function (res) {
                    that.$message({
                        showClose: true,
                        message: '查询过磅记录异常，请联系管理员',
                        type: 'error'
                    });
                    return;
                },
                complete: function (XMLHttpRequest, status) {
                    that.tableLoading = false;
                }
            })
        },
        doOrder(code) {
            let that = this;
            if (isNull(code)) {
                that.$message({
                    showClose: true,
                    message: '请选择数据',
                    type: 'error'
                });
                return;
            }
            that.tableLoading = true;
            $.ajax({
                type: "PUT",
                url: "/weight/order/unskinned/do/" + code,
                async: true,
                dataType: 'json',
                success: function (res) {
                    if (res.code == 0) {
                        that.loadTableDatas();
                    } else {
                        that.$message({
                            showClose: true,
                            message: '操作过磅订单失败：' + res.msg,
                            type: 'error'
                        });
                    }
                },
                error: function (res) {
                    that.$message({
                        showClose: true,
                        message: '操作过磅订单异常，请联系管理员',
                        type: 'error'
                    });
                    return;
                },
                complete: function (XMLHttpRequest, status) {
                    that.tableLoading = false;
                }
            })
        },
        // 修改每页数据
        handleSizeChange(val) {
            var that = this;
            that.tableSearch.limit = val;
            // 查询数据
            that.loadTableDatas();
        },
        handleCurrentChange(val) {
            // 设置页数
            var that = this;
            that.tableSearch.offset = val;
            that.loadTableDatas();
        },
    }
})
